<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <script>
      (function () {
        /*
                判断对象是否相同
            */
        let obj = { a: 1 };
        let obj2 = { a: 1 };
        //此方法只适合完全相同 即表示key value 顺序一样
        console.log(JSON.stringify(obj) === JSON.stringify(obj2));

        // 列出所有的键，接着遍历数组
        function ifCompare(object1, object2) {
          let o1keys = Object.keys(object1);
          let o2keys = Object.keys(object2);
          if (o2keys.length !== o1keys.length) return false;
          for (let i = 0; i <= o1keys.length - 1; i++) {
            let key = o1keys[i];
            if (!o2keys.includes(key)) return false;
            if (object2[key] !== object1[key]) return false;
          }
          return true;
        }
        //Object.entries 进行判断  a,1,
        console.log(Object.entries(obj).toString() === Object.entries(obj2).toString());
      })();
    </script>
  </body>
</html>
